import {addDay, dateFormatWithFmt, getTimeDuring, isNull} from "@/utils/common.js"

export function genNoticeDetail(type, data, activityName, orgName) {
    const {
        report,
        activitymessage,
        listtarget,
        creattime
    } = data;
    const targetList = listtarget.splice(0, 3);
    let target1st = "活动相关指标";
    if (listtarget && listtarget.length > 0) {
        const newTargetData = targetList.map(item => {
            return item.NAME;
        }).join("、");
        target1st = newTargetData + "等";
    }
    let result = "";
    result += "<!DOCTYPE html>\n";
    result += "<html>\n";
    result += "<head>\n";
    result += "<meta charset=\"UTF-8\">\n";
    result += "<title></title>\n";
    result += "</head>\n";
    result += "<body>\n";
    result += "<br />\n";
    result += "<div style=\"text-align: center;color: red;font-size: 50px;\">贵阳市人民政府教育督导室办公室文件</div>\n";
    result += "<hr style=\"height:2px;border:none;border-top:2px ridge red;\" />\n";
    result += "<div style=\"text-align: center;color: black;font-size: 25px;font-weight: bold;\">关于对" + activityName +
        "</div>\n";
    result += "<div style=\"text-align: center;color: black;font-size: 25px;font-weight: bold;\">整改通知书</div>\n";
    result += "<br />\n";
    if (type == 1) {
        result += "<div style=\"text-align: left;color: black;font-size: 20px;\">" + orgName + "：</div>\n";
        result += "<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;根据《" + activityName + "》统一安排，市级视导组于" + getTimeDuring(activitymessage
                .beginTime) + "，通过“听、看、查、访、问”等方式，对你校" + target1st +
            "工作开展情况进行了实地视导。现将视导中发现的问题清单列出，请逐一对标，抓好问题的整改落实；同时，要举一反三，有针对性地核查其他指标是否存在类似问题，并做好指导和管理，确保工作有序开展。</p>\n";
    } else {
        result += "<div style=\"text-align: left;color: black;font-size: 20px;\">" + orgName +
            "政府教育督导室、教育局：</div>\n";
        result += "<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;根据《" + activityName + "》统一安排，市级视导组于" + getTimeDuring(activitymessage
                .beginTime) + "，通过“听、看、查、访、问”等方式，对你区" + target1st +
            "工作开展情况进行了实地视导。现将视导中发现的问题清单列出，请逐一对标，抓好问题的整改落实；同时，要举一反三，有针对性地核查其他学校是否存在类似问题，并做好指导和管理，确保工作有序开展。</p>\n";
    }
    const formatDate = dateFormatWithFmt(new Date(addDay(creattime, 7)), "yyyy年MM月dd日");
    result += "<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;请于" + formatDate + "前将问题整改落实情况书面报送" +
        "所区县所属政府教育督导室办公室，每月视导检查出现的问题整改落实情况做为“双线目标”考核依据。</p>\n";
    result += "<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;联系人：林兰 电话：13608567878 </p>\n";
    result += "<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;附件：" + activityName + "问题清单</p>\n";
    result += "<br />\n";
    result += "<br />\n";
    result += "<p style=\"text-align: right;\">贵阳市人民政府教育督导室办公室&nbsp;&nbsp;</p>\n";
    result += "<p style=\"text-align: right;\">" + dateFormatWithFmt(new Date(creattime), "yyyy年MM月dd日") +
        "&nbsp;&nbsp;&nbsp;&nbsp;</p>\n";
    result += "<br />\n";
    result += "<br />\n";
    result += "<br />\n";
    result += "<br />\n";
    result += "<br />\n";
    result += "<br />\n";
    result += "<br />\n";
    result += "<br />\n";
    result += "<br />\n";
    result += "<br />\n";
    result += "<br />\n";
    result += "<br />\n";
    result += "<br />\n";
    result += "<br />\n";
    result += "<br />\n";
    result += "<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;附件：</p>\n";
    result += "<div style=\"text-align: center;color: black;font-size: 25px;font-weight: bold;\">" + activityName +
        "问题清单</div>\n";

    result += "<table border=\"1\"  cellSpacing=\"0\" width=\"88%\" align=\"center\">\n";
    result += "<tr>\n";
    result += "<th style=\"width: 20%;\" align=\"center\">单位名称</th>\n";
    result += "<th style=\"width: 60%;\">存在的问题</th>\n";
    result += "<th style=\"width: 20%;\">备注</th>\n";
    result += "</tr>\n";

    if (type == 1) {
        result += "<tr>\n";
        result += "<td style=\"width: 20%;\" align=\"center\">" + orgName + "</td>\n";
        result += "<td style=\"width: 60%;\">";
        report.forEach(item => {
            if (isNull(item.content)) {
                result += "<p>" + item.name + "存在问题</p>\n";
            } else {
                result += "<p>" + item.name + "存在" + (item.content || "") + "的问题</p>\n";
            }
        });
        result += "</td>\n";
        result += "<td style=\"width: 20%;\"></td>\n";
        result += "</tr>\n";
    } else {
        let schooleName = report[0].xxmc;
        result += "<tr>\n";
        result += "<td style=\"width: 20%;\" align=\"center\">" + schooleName + "</td>\n";
        result += "<td style=\"width: 60%;\">";
        report.forEach(item => {
            if (item.xxmc === schooleName) {
                result += "<p>" + item.name + "存在" + (item.content || "") + "的问题</p>\n";
            } else {
                schooleName = item.xxmc;
                result += "<td style=\"width: 20%;\"></td>\n";
                result += "</tr>\n";
                result += "<tr>\n";
                result += "<td style=\"width: 20%;\" align=\"center\">" + schooleName + "</td>\n";
                result += "<td style=\"width: 60%;\">";
            }
        });
        result += "</td>\n";
        result += "<td style=\"width: 20%;\"></td>\n";
        result += "</tr>\n";
    }
    result += "</table>\n";
    result += "<br />\n";
    result += "<br />\n";
    result += "</body>\n";
    result += "</html>";
    return result;
}